// 数据仓库
package task

import (
	"teamJDI/database"

	"labix.org/v2/mgo/bson"
)

func TaskExists(task_form *TaskForm) *Task {
	var _task Task
	database.DB.Where("content = ? AND handler_id = ?",
		task_form.Content, task_form.HandlerID).First(&_task)
	return &_task
}

func CreateTask(task_form *TaskForm) int {
	var _task Task
	json_str, _ := bson.Marshal(task_form)
	bson.Unmarshal(json_str, &_task)
	if err := database.DB.Create(&_task); err.Error != nil {
		return 0
	}
	return _task.ID
}
